Skip to content

Code reads use only the mirror of the namespace's own repository entry - #2061

Open
zlareb1 wants to merge 7 commits into
mainfrom
fix/code-reads-own-entry-mirror
Open

zlareb1 wants to merge 7 commits into
mainfrom
fix/code-reads-own-entry-mirror

Conversation

@zlareb1

@zlareb1 zlareb1 commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

A code read from any org, naming a namespace without a repository entry, no longer answers from the deployment's default repository mirror (blame, PR numbers, commit subjects, diffs).

Why

A code read resolves its git mirror from the namespace's repository entry. When the namespace had no entry, four sites fell back to the scalar entry's mirror (LOOM_CODE_*, through repos.default_git_dir()), and the fallback did not check the caller's org or namespace:

  • blame.history_git_dir, which code.blame_range, code.first_build and the mark and fix-blame stages of code.bisect_candidates read through
  • the merge-sha stage of code.bisect_candidates (bisect._attach_merge_shas)
  • code.verify_citations (citations._git_legs)
  • at_commit reads of code.tests_for and code.test_gate (at_commit._mirror), limited to the scalar entry's org

So a caller in any org, naming a namespace no entry indexes, got the history of the scalar entry's repository: PR numbers, commit subjects, blame and diff marks. The history bound did not limit it: a namespace with no indexed head is unbounded, and from_sha / to_sha name the window directly.

The fix deletes the fallback. mirrors.history_dir(None) answers no_git_mirror: the namespace has no repository entry, every history read goes through history_dir, and the wrappers that existed only for the fallback are deleted (repos.default_git_dir, blame.history_git_dir). An entry-less read then takes the paths a namespace without a mirror already takes.

The scalar entry's branch (LOOM_CODE_GIT_BRANCH) is not applied to a namespace with no entry either. code.conventions compared a ledger row's target_branch with it, so a PR the ledger says merged into another branch read as off the namespace's branch. A namespace with no entry has no branch, and target_branch is compared only when there is one. Outside repos.py, no server code reads code_git_branch, and the repository-snapshot gate now enforces it. The cfg is not None guards that only the fallback reached are removed from blame and citations: past the mirror gate, the namespace has an entry. bisect._attach_merge_shas is keyed on the mirror history_dir returns instead: with no entry, or no mirror on this host yet, it returns the ledger's merge shas and skips the indexed-head read, which the mirror search alone uses. dupcheck_links drops a guard history_dir(None) already covers.

at_commit, bad_sha on code.bisect_candidates and the history stage of code.backport_gap answer an entry-less namespace with the same text as every other site, no_git_mirror: the namespace has no repository entry.

Scope and risk

  • Touches the history reads of the code plane: code.blame_range, code.bisect_candidates (marks, merge shas, fix blame), code.first_build, code.verify_citations, code.conventions, code.backport_gap (history=true), at_commit on code.tests_for and code.test_gate, code.reindex and code.index_status.
  • The scalar entry's own namespace still reads its mirror (positive controls in the unit and integration tests).
  • code.reindex wrote git_head to any namespace. No ingest walks a namespace with no entry, so it answers that namespace as not configured (404), as code.refresh does.
  • code.index_status of a namespace with index rows but no entry named the scalar entry's repository and branch. It names none. Its commit check named the status stand-in's missing remote; it names the missing entry.
  • Left alone: loom code backfill with no --namespace, when LOOM_CODE_NAMESPACE has no entry, indexes the first configured entry under the deployment's code namespace. That is an operator command run with deployment credentials, not a read path; it never depended on this fallback.

Compatibility, rollout and rollback

  • Wire: no op or field is added or removed. Behaviour changes for a namespace no repository entry indexes:
    • code.blame_range, code.first_build, code.verify_citations and the code.bisect_candidates marks and fix-blame stage answer with the gap no_git_mirror: the namespace has no repository entry and read no mirror. On a host with git history off (LOOM_GIT_HISTORY=none), code.blame_range answers no_git_history first, as before.
    • code.backport_gap with history=true gives each branch row's history the reason no_git_mirror: the namespace has no repository entry. It gave no_branch_ref.
    • code.conventions notes no_git_mirror: the namespace has no repository entry: diff-dependent rules are unknown and sets no off_branch from the scalar entry's branch, so bugfix_has_test and stateless_test_number are judged as for a PR on the namespace's own branch. Its ledger reads drop the branch filter too, since an empty branch adds no target_branch predicate: the changelog_category census and the stateless_test_number first-owner lookup count the namespace's ledger rows of every branch.
    • at_commit, for a namespace with an indexed head, still answers the indexed head's full sha with no mirror read, and is refused for any other commit with 422 "at_commit reads the namespace's git mirror: no_git_mirror: the namespace has no repository entry" in every org, the scalar entry's included. A namespace with no indexed head still answers "the namespace has no indexed head" first.
    • code.bisect_candidates with bad_sha and no before answers 422 BAD_SHA "no_git_mirror: the namespace has no repository entry; pass before as a time instead". It said " has no repository mirror to resolve ".
    • code.reindex answers 404 RESOURCE_NOT_FOUND "namespace / has no repository entry, so no ingest walks it".
    • code.index_status answers an empty repo and branch, provider git and profile generic (they were derived from the scalar entry's repository), and a commit check waits on commit not checked: no_git_mirror: the namespace has no repository entry. With an empty branch, a published clone_head row (which names its branch) and the published lags no longer match, so clone_head is empty and the lags read -1 (unknown).
  • Operator steps: none. A deployment whose readers relied on the fallback gives the namespace a repository entry (LOOM_CODE_REPOS_JSON or the self-service registry).
  • Rollback: reverting restores the fallback and leaves nothing behind. No rows or migrations change, and the regenerated docs/reference/operations/code.md reverts with the rest.

Tests

  • Unit, one per site, each failing on main and passing here. Each runs an entry-less namespace in another org and one in the scalar entry's org, except two single cases: test_code_bisect_before.py, with repo_for_namespace stubbed to None, and test_code_backport_gaps.py, an unlisted namespace of the entry's org. The blame range, mirrors, first build, citations and at_commit tests assert that git never runs with the scalar entry's directory and that the scalar entry's own namespace still reads it. The conventions positive control is a stub entry (_Cfg) on master, and the reindex file has a separate test for the entry's own namespace:
    • tests/unit/test_code_blame_range.py
    • tests/unit/test_mirrors.py (bisect marks, merge shas, fix blame)
    • tests/unit/test_code_first_build.py
    • tests/unit/test_code_verify_citations_resolve.py and tests/unit/test_code_at_commit.py, whose positive control reads the scalar entry's mirror through the unpatched history_dir
    • tests/unit/test_code_conventions.py: with LOOM_CODE_GIT_BRANCH=master and a ledger row merged into main, bugfix_has_test is violated, not not_applicable. Its positive control, an entry on master, reads the same row as not_applicable with the note "merged into main, not master"; forcing the branch to "" in conventions.py fails it.
    • tests/unit/test_code_reindex_scope.py (404)
    • tests/unit/test_code_bisect_before.py: bad_sha in a namespace with no entry answers BAD_SHA with the shared text, runs no git and scans nothing. On main it gets "code-clickhouse has no repository mirror to resolve 'abc1234'".
    • tests/unit/test_code_status_ops.py (repository, branch and the commit check)
    • tests/unit/test_code_backport_gaps.py: the history stage of a namespace with no entry names the missing entry on each branch row; the entry's own namespace reads its release branch on a real mirror and decides gap. On main the row says no_branch_ref.
  • tests/unit/test_code_bisect_frameless.py gives its namespace an entry with a mirror. The test then shows that the frameless pool alone keeps the diffs from running; on main the missing mirror did.
  • tests/unit/test_code_bisect_deadline.py gives its namespace an entry too, whose mirror history_dir serves. Without one, the fix-blame stage stops at the gap before it reaches the slow blame the test times.
  • tests/unit/test_repo_snapshot_contract.py now lists code_git_branch and code_git_remote beside code_git_dir and _scalar_repo, and an attribute read of code_repo: outside repos.py and the settings, no server module reads them. A getattr of any of them by a literal name counts too. A probe in the test asserts that settings.code_git_branch, settings.code_repo, getattr(settings, 'code_git_remote') and getattr(settings, 'code_repo', '') are flagged and that a local variable named code_repo is not.
  • Integration: tests/integration/test_code_default_mirror_isolation.py builds a bare mirror at the clone path of the entry of the deployment's code namespace (repos.config_entry; skipped when no entry indexes it), with a commit squash-merged as PR 7 whose subject carries a nonce. It first calls code.blame_range over HTTP as the deployment's code namespace, which gets PR 7; when that read answers no_git_mirror: (the server does not see this checkout's mirror) or no_git_history: (the host keeps no mirrors), the test skips. It removes the mirror, and the directories it made for it once they are empty. It then calls it from another org and from an unlisted namespace of the same org. Both answer the gap with no candidates and no nonce. Against a server running main both cases fail: the window resolves on the scalar entry's mirror. Against this branch, on a ClickHouse started for the run, the file passes (2 passed).
  • make format lint typecheck pass. The code-plane unit files this change touches (blame, bisect, merge shas, sha inputs, duplicate-check links, citations, conventions, first build, status, at_commit, reindex, mirrors, test gate, tests for) and the copy, link, inventory, package-contract and repository-snapshot gates: 1599 passed. 5 failed in tests/unit/test_mirror_names_refused.py, a migration test that runs SQL through the local clickhouse binary, which rejects the setting enable_quantized_codec; the test reads none of the code this change touches.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The diagnosis, each site's test failing on main and the integration run against both builds were checked before the push.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.
  • I signed the Contributor License Agreement (CLA) if CLA assistant requested a signature.

🤖 Generated with Claude Code

A code read whose namespace had no repository entry fell back to the
deployment's scalar entry's mirror (`LOOM_CODE_*`) without checking the
org or namespace, so a caller in any org could read that repository's
history through code.blame_range, code.bisect_candidates,
code.verify_citations and code.first_build, and a namespace of the
scalar entry's org could read it through `at_commit`.

`mirrors.history_dir` answers `no_git_mirror: the namespace has no
repository entry` for an entry-less namespace, and every history read
goes through it. `repos.default_git_dir` and `blame.history_git_dir`
are deleted. `at_commit` refuses an entry-less namespace as naming no
repository, code.reindex refuses one (it has no watermark to move), and
code.index_status names no repository or branch for one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Dec 3, 2026 11:25am UTC
loom-telemetry Ready Ready Preview Dec 3, 2026 11:25am UTC

Request Review

zlareb1 and others added 6 commits December 3, 2026 13:36
…r entry

code.conventions compared a ledger row's target branch with the scalar
entry's branch (`LOOM_CODE_GIT_BRANCH`) for a namespace with no entry, so a
PR merged into another branch read as off the namespace's branch and its
bugfix_has_test and stateless_test_number verdicts became not_applicable.
Such a namespace has no branch, and the target branch is compared only
when there is one.

A code.index_status commit check of a namespace with no entry passed the
status stand-in to history_dir and answered that it names no remote; it
passes the entry, so the check names the missing entry. code.reindex of
such a namespace answers 404, as code.refresh does. The None guards and
scalar-branch fallbacks the deleted mirror fallback left in blame, bisect,
citations and conventions are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ry text

Every other history read answers a namespace no repository entry indexes
with `no_git_mirror: the namespace has no repository entry`; `at_commit`
said "the namespace names no repository". It raises `mirrors.NO_REPO_ENTRY`,
and its one-caller `_mirror` helper is inlined into `resolve`, so the
retry-or-refuse decisions read in one place.

The conventions test covers a namespace in another org and one in the
scalar entry's org, with a positive control on an entry's own branch. The
integration test builds the mirror of the entry `repos.config_entry`
names for the deployment's code namespace, so a `LOOM_CODE_REPOS_JSON`
entry that replaces the scalar one is the one it reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… and repo

Outside `repos.py` and the settings, no server module reads
`code_git_branch` or `code_git_remote`; the gate now lists them beside
`code_git_dir` and `_scalar_repo`. `code_repo` also names local variables,
so only an attribute read of it counts.

The `at_commit` docstring states when a read is refused as the operations
page does: a commit the mirror lacks is refused for every entry, and what
the mirror lacks is refused when this host neither clones nor fetches it.
The `at_commit` test reaches the unpatched `history_dir` through
`_HISTORY_DIR` alone, and two edited texts are wrapped to their paragraphs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… text

`code.bisect_candidates` with `bad_sha` and no `before` answered a
namespace no repository entry indexes with "<ns> has no repository mirror
to resolve <sha>". The pre-check is deleted: `history_dir(None)` answers
`no_git_mirror: the namespace has no repository entry`, and the refusal
keeps `BAD_SHA` and its "pass `before` as a time instead".

`bisect._attach_merge_shas` is keyed on the mirror `history_dir` returns
rather than on the entry, so with no mirror on this host it skips the
indexed-head read the mirror search alone uses.

The repository-snapshot gate's predicate is a function with a probe: a
`settings.code_git_branch` or `settings.code_repo` read is flagged, and a
local variable named `code_repo` is not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…remote server

The integration test's positive read runs first: when it answers
`no_git_mirror:`, the server under test does not see this checkout's
mirror, so the test skips rather than passing the entry-less cases on a
server that reads no mirror at all.

The repository-snapshot gate counts a `getattr` of the raw configuration
by a literal name, with a probe. `mirrors.NO_REPO_ENTRY` is exported,
`dupcheck_links` drops a guard `history_dir(None)` already covers, and
`_attach_merge_shas` sets the mirror and the ref on separate lines.

The operations page says a namespace no entry indexes is refused for any
commit but the indexed head's, and the architecture page says the no-entry
text is `history_dir`'s answer and that the PR overlay answers
`overlay_note: no_repo_entry` before it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
`_history_stage` asked `history_dir` only when the namespace had an entry,
so with `history=true` a namespace no repository entry indexes read
branches from an empty mirror path and each row said `no_branch_ref`. It
now asks `history_dir` either way, and the rows carry
`no_git_mirror: the namespace has no repository entry`.

The isolation test also skips when the entry's own read answers
`no_git_history:` (a host that keeps no mirrors), and it removes the
directories it made for the mirror once they are empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant